<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-09-04 16:18:08
 * @LastEditTime: 2019-09-16 11:01:05
 * @LastEditors: Please set LastEditors
 -->
<template>
  <div>
      <camera device-position="back" flash="off" style="width: 100%; height: 84vh;"></camera>
      <button type="primary" @click="takePhoto">拍照</button>
  </div>
</template>


<script>
const util = require('../../utils/util.js')
const apis = require('../../utils/api.js').default
export default {
  data(){
    return{
      type:''
    }
  },
  onLoad:function(options){
    this.type = options.type;
    this.ctx = wx.createCameraContext();
  },
  methods:{
    takePhoto() {
      wx.showLoading({
        title: '拍摄中~',
      })
      let _this = this;
      this.ctx.takePhoto({
        quality: 'high',
        success: (res) => {
          // apis.upFiles(wx.getFileSystemManager().readFileSync(res.tempImagePath, "base64"))
          wx.hideLoading()
          wx.showLoading({
            title: '图片上传中~',
          })

          apis.upFiles({filePath:res.tempImagePath,type:_this.type,callback:function(resy){
                wx.hideLoading()
                wx.setStorageSync('loslist',resy)
                wx.navigateTo({
                     url:"../fructify/main"
                 })
          }})
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
camera{
  width: 90%;
  display: block;
  margin: 0 auto;
}
button{
  width: 80%;
  margin-top:50rpx; 
}
</style>

